<!--

    Copyright 2020 StreamSets Inc.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="description" content="StreamSets">
  <title ng-bind="common.title">StreamSets</title>

  <script type="text/javascript">
    function escapeHtml(str) {
      var div = document.createElement('div');
      div.appendChild(document.createTextNode(str));
      return div.innerHTML;
    }

    var baseHref = document.location.pathname.replace('j_security_check', ''),
      collectorIndex = baseHref.indexOf('/collector/');

    if(collectorIndex !== -1) {
      baseHref = baseHref.substr(0, collectorIndex + 1);
    } else {
      var restIndex = baseHref.indexOf('/rest/');
      if(restIndex !== -1) {
        baseHref = baseHref.substr(0, restIndex + 1);
      }
    }

    document.write("<base href='" + escapeHtml(baseHref) + "' />");
  </script>

  <link rel="icon" type="image/png" href="assets/favicon.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <!-- compiled CSS --><% styles.forEach( function ( file ) { %>
  <link rel="stylesheet" type="text/css" href="<%= file %>" /><% }); %>
</head>
<body>

  <div class="container login-container">
    <div class="row">
      <div id="loginErrorMessageDivId"
           class="col-xs-6 col-xs-offset-3 col-sm-5 col-sm-offset-4 col-md-4 col-md-offset-4 col-lg-4 col-lg-offset-4 alert alert-danger"
           role="alert">Log In Failed.</div>
    </div>

    <div class="row">
      <div
        class="col-xs-6 col-xs-offset-3 col-sm-5 col-sm-offset-4 col-md-4 col-md-offset-4 col-lg-4 col-lg-offset-4 form-login">
        <form class="form-horizontal clearfix" action="j_security_check"
              autocomplete="off"
              method="POST">
          <div class="img_container">
            <img src="assets/logo.png" />
          </div>
          <input style="display:none">
          <input type="password" style="display:none" autocomplete="off">
          <input type="text" id="usernameId" name="j_username" class="form-control" placeholder="username"
                 autofocus="true"/>
          <input type="password" id="passwordId" name="j_password" class="form-control" placeholder="password"
                 autocomplete="off"/>
          <input type="hidden" id="basePathInputID" name="basePath" class="form-control" value="" />
          <button type="submit" id="loginId"
                  class="btn btn-primary pull-right">Log In <i class="fa fa-sign-in"></i></button>
        </form>
      </div>
    </div>
  </div>

  <script>
    var pathname = window.location.pathname;
    if(pathname && pathname.indexOf('j_security_check') !== -1) {
      var errorDiv = document.getElementById('loginErrorMessageDivId');
      errorDiv.style.visibility = 'visible';
    }

    var basePathInput = document.getElementById("basePathInputID");
    if(basePathInput) {
      basePathInput.value = baseHref;
    }
  </script>

</body>
</html>
